import gql from 'graphql-tag';

/** 登录请求验证码 */
export const LOGIN_requestVerifyCode = gql`
  mutation ($input: UserRequestLoginVerifyCodeInput!) {
    userRequestLoginVerifyCode(input: $input)
  }
`;

/** 通过验证码实现手机登录 */
export const LOGIN_phoneLoginWithCode = gql`
  mutation userPhoneLoginWithCode($input: PhoneLoginInput!) {
    userPhoneLogin(input: $input) {
      user {
        id
        name
        phone
      }
      userList {
        id
        name
      }
    }
  }
`;

/** 第二步：拿取userList中对应用户id值，进行id登录 */
export const LOGIN_userPhoneLogin = gql`
  mutation userPhoneLogin($input: PhoneLoginInput!) {
    userPhoneLogin(input: $input) {
      user {
        id
        name
        phone
        roles {
          id
          name
          type
        }
        userRoles {
          id
          role_id
          organ_id
          organ {
            id
            name
          }
          role {
            id
            name
            type
          }
        }
      }
    }
  }
`;

export const LOGIN_LoginWithPassword = gql`
  mutation userPhoneLoginWithPassword($input: PhoneLoginInput!) {
    userPhoneLogin(input: $input) {
      user {
        id
        name
        phone
        roles {
          id
          name
          type
        }
      }
      userList {
        id
        name
      }
    }
  }
`;

/** 重置密码验证码 */
export const USER_resetPasswordVerifyCode = gql`
  mutation userRequestResetPasswordVerifyCode($input: UserRequestResetPasswordVerifyCodeInput!) {
    userRequestResetPasswordVerifyCode(input: $input)
  }
`;

/** 重置密码验证码 两步的 先请求userlist */
export const USER_resetPasswordVerifyCodeList = gql`
  mutation userRequestResetPasswordVerifyCode($input: UserRequestResetPasswordVerifyCodeInput!) {
    userRequestResetPasswordVerifyCode(input: $input) {
      success
      userList {
        id
        name
      }
    }
  }
`;

/** 重置密码 */
export const USER_ResetPassword = gql`
  mutation userResetPassword($input: UserResetPasswordInput!) {
    userResetPassword(input: $input)
  }
`;

/** 用户注册 */
export const USER_Signup = gql`
  mutation userSignup($input: UserSignupInput!) {
    userSignup(input: $input) {
      id
      name
    }
  }
`;

/** 用户注册发送验证码 */
export const USER_requestVerifyCode = gql`
  mutation ($input: UserRequestSignupVerifyCodeInput!) {
    userRequestSignupVerifyCode(input: $input)
  }
`;

/** 退出登录 */
export const USER_UserLogOut = gql`
  mutation UserLogOut {
    userLogOut {
      success
    }
  }
`;

export const listSchoolUsers = gql`
  query listSchoolUsers(
    $type: NodeListType!
    $organ_id: ID!
    $role_id: ID
    $expand_organ_user: Boolean
  ) {
    nodeList(
      type: $type
      organ_id: $organ_id
      role_id: $role_id
      expand_organ_user: $expand_organ_user
    ) {
      ... on User {
        id
        name
        phone
        userRoles {
          role {
            name
          }
        }
        childUserList {
          id
          name
        }
      }
    }
  }
`;

/** 图片上传 */
export const userRequestUploadURL = gql`
  mutation userRequestUploadURL($input: UserRequestUploadURLInput!) {
    userRequestUploadURL(input: $input) {
      success
      signed_url
      url
      object_key
      mime_type
    }
  }
`;

export const userSaveUploadLog = gql`
  mutation userSaveUploadLog($input: UserSaveUploadLogInput!) {
    userSaveUploadLog(input: $input) {
      success
    }
  }
`;

export const deleteOrgan = gql`
  mutation adminUpdateOrganInfo($input: AdminUpdateOrganInput!) {
    adminUpdateOrganInfo(input: $input) {
      id
      name
      type
      location
      removedAt
    }
  }
`;

export const updateOrgan = gql`
  mutation adminUpdateOrganInfo($input: AdminUpdateOrganInput!) {
    adminUpdateOrganInfo(input: $input) {
      id
      name
    }
  }
`;

export const adminCreateOrganInfo = gql`
  mutation adminCreateOrganInfo($input: AdminCreateOrganInput!) {
    adminCreateOrganInfo(input: $input) {
      id
      name
    }
  }
`;
